package jnpf.permission.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import jnpf.permission.entity.OrganizeAdminIsTratorEntity;
import jnpf.permission.entity.OrganizeEntity;
import jnpf.permission.mapper.OrganizeAdminIsTratorMapper;
import jnpf.permission.service.OrganizeAdminIsTratorService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import jnpf.util.DateUtil;
import jnpf.util.UserProvider;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 *
 * 机构分级管理员
 * @author JNPF开发平台组
 * @version V3.1.0
 * @copyright 引迈信息技术有限公司
 * @date 2019年9月26日 上午9:18
 */
@Service
public class OrganizeAdminIsTratorServiceImpl extends ServiceImpl<OrganizeAdminIsTratorMapper, OrganizeAdminIsTratorEntity> implements OrganizeAdminIsTratorService {

    @Autowired
    private UserProvider userProvider;


    @Override
    public OrganizeAdminIsTratorEntity getUserId(String userId,String organizeId){
        QueryWrapper<OrganizeAdminIsTratorEntity> queryWrapper = new QueryWrapper<>();
        queryWrapper.lambda().like(OrganizeAdminIsTratorEntity::getUserId,userId);
        queryWrapper.lambda().eq(OrganizeAdminIsTratorEntity::getOrganizeId,organizeId);
        return this.getOne(queryWrapper);
    }

    @Override
    public List<OrganizeAdminIsTratorEntity> getOrganizeAdminIsTratorEntity(String userId){
        QueryWrapper<OrganizeAdminIsTratorEntity> queryWrapper = new QueryWrapper<>();
        queryWrapper.lambda().like(OrganizeAdminIsTratorEntity::getUserId,userId);
        List<OrganizeAdminIsTratorEntity> list = this.list(queryWrapper);
        return list;
    }

    @Override
    public void create(OrganizeAdminIsTratorEntity entity){
        QueryWrapper<OrganizeAdminIsTratorEntity> queryWrapper = new QueryWrapper<>();
        entity.setCreatorUserId(userProvider.get().getUserId());
        this.save(entity);
    }

    @Override
    public boolean update(String organizeId, OrganizeAdminIsTratorEntity entity) {
        entity.setId(entity.getId());
        entity.setLastModifyTime(DateUtil.getNowDate());
        entity.setLastModifyUserId(userProvider.get().getUserId());
//        queryWrapper.lambda().eq(OrganizeAdminIsTratorEntity::getOrganizeId, organizeId);
        return this.updateById(entity);
    }

    @Override
    public OrganizeAdminIsTratorEntity getInfo(String id) {
        QueryWrapper<OrganizeAdminIsTratorEntity> queryWrapper = new QueryWrapper<>();
        queryWrapper.lambda().eq(OrganizeAdminIsTratorEntity::getId, id);
        return this.getOne(queryWrapper);
    }

    @Override
    public void delete(OrganizeAdminIsTratorEntity entity) {
        this.removeById(entity.getId());
    }

    @Override
    public OrganizeAdminIsTratorEntity getInfoByOrganizeId(String organizeId) {
        QueryWrapper<OrganizeAdminIsTratorEntity> queryWrapper = new QueryWrapper<>();
        queryWrapper.lambda().eq(OrganizeAdminIsTratorEntity::getOrganizeId, organizeId);
        return this.getOne(queryWrapper);
    }

}
